<?php

$url = explode("/", $_SERVER['HTTP_REFERER']);
if (strcmp($url[count($url) - 1], 'submit.php') != 0) {
  $is_indirect_link = true;
}

// Report all errors and ignor notices
error_reporting(E_ALL ^ E_NOTICE);

// Disable magic_quotes_runtime
set_magic_quotes_runtime(0);

// Set default timezone
date_default_timezone_set("Asia/Taipei");

$phpver = phpversion();
if ($phpver < '4.1.0') {
  $_GET = $HTTP_GET_VARS;
  $_POST = $HTTP_POST_VARS;
  $_SERVER = $HTTP_SERVER_VARS;
}
$phpver = explode(".", $phpver);
$phpver = "$phpver[0]$phpver[1]";
if ($phpver >= 41) {
  $PHP_SELF = $_SERVER['PHP_SELF'];
}

//Set root path
$ROOT_DIR = realpath(dirname(__FILE__));
$ROOT_DIR = str_replace('\\', '/', $ROOT_DIR);

if (!$is_indirect_link) {
  $is_page_valid = true;
}
else {
  $is_page_valid = false;
}

session_start();

if (!isset($_SESSION['is_page_valid'])) {
  // Validate form data
  $error_msg = '';
  if (strcmp(trim($_POST['username']), "") == 0)  {
    $error_msg = $error_msg . '請填寫姓名<br />';
    $is_page_valid = false;
  }
  else {
    if (mb_strlen(trim($_POST['username']), 'UTF-8')  == 1) {
      $error_msg = $error_msg . '姓名不合法<br />';
      $is_page_valid = false;
    }
  }
  if (strcmp(trim($_POST['affiliation']), "") == 0)  {
    $error_msg = $error_msg . '請填寫單位<br />';
    $is_page_valid = false;
  }
  else {
    if (mb_strlen(trim($_POST['affiliation']), 'UTF-8')  == 1) {
      $error_msg = $error_msg . '單位不合法<br />';
      $is_page_valid = false;
    }
  }
  if (strcmp(trim($_POST['title']), "") != 0)  {
    if (mb_strlen(trim($_POST['title']), 'UTF-8')  == 1) {
      $error_msg = $error_msg . '職稱不合法<br />';
      $is_page_valid = false;
    }
  }
  if (strcmp(trim($_POST['telephone']), "") != 0)  {
    $islocal = false;
    $ismobile = false;
    if (preg_match("/^0\d{1,2}-\d{6,8}/", trim($_POST['telephone']))) {
      $islocal = true;
    }
    if (preg_match("/^09\d{8}$/", trim($_POST['telephone']))) {
      $ismobile = true;
    }
    if (!$islocal && !$ismobile) {
      $error_msg = $error_msg . '電話號碼不合法<br />';
      $is_page_valid = false;
    }
  }
  if (strcmp(trim($_POST['email']), "") == 0)  {
    $error_msg = $error_msg . '請填寫電子郵件<br />';
    $is_page_valid = false;
  }
  else {
    if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", trim($_POST['email']))) {
      $error_msg = $error_msg . '電子郵件不合法<br />';
      $is_page_valid = false;
    }
  }
  if (strcmp(trim($_POST['division']), "") == 0)  {
    $error_msg = $error_msg . '請填寫參加組別<br />';
    $is_page_valid = false;
  }
  else {
    if (strcmp(trim($_POST['division']), 'other') == 0) {
      if (strcmp(trim($_POST['other_division']), '') == 0) {
        $error_msg = $error_msg . '請註明其他組別<br />';
        $is_page_valid = false;
      }
    }
  }
  if (strcmp(trim($_POST['presentation_type']), "") == 0)  {
    $error_msg = $error_msg . '請填寫投稿類別<br />';
    $is_page_valid = false;
  }
  if (!is_null($_POST['equipment'])) {
    if (strcmp($_POST['equipment'][count($_POST['equipment'])-1], 'other') == 0) {
      if (strcmp(trim($_POST['other_equipment']), '') == 0) {
        $error_msg = $error_msg . '請註明其他器材<br />';
        $is_page_valid = false;
      }
    }
  }
}

if (isset($_SESSION['is_page_valid'])) {
  $is_page_valid = $_SESSION['is_page_valid'];
}

if ($is_page_valid) {
  include("$ROOT_DIR/config.php");
  include("$ROOT_DIR/mysql_class.php");
  $db = new sql_db($db_host, $db_username, $db_password, $databse_name, false);

  if (!$db->db_connect_id) {
    echo mysql_error();
    session_unset();
    session_destroy();
    exit('無法連接資料庫！');
  }

  if (!isset($_SESSION['is_page_valid'])) {
    $_SESSION['is_page_valid'] = $is_page_valid;
    $_SESSION['error_msg'] = $error_msg;

    $_SESSION['username'] = trim($_POST['username']);
    $_SESSION['affiliation'] = trim($_POST['affiliation']);
    $_SESSION['title'] = trim($_POST['title']);
    $_SESSION['telephone'] = trim($_POST['telephone']);
    $_SESSION['email'] = trim($_POST['email']);
    $_SESSION['division'] = $_POST['division'];
    $_SESSION['other_division'] = trim($_POST['other_division']);
    $_SESSION['presentation_type'] = $_POST['presentation_type'];
    $_SESSION['equipment'] = $_POST['equipment'];
    $_SESSION['other_equipment'] = trim($_POST['other_equipment']);

    if (isset($_POST['confirm_presentation_type'])) { header("Location: submit.php"); }
  }

  if (isset($_POST['submit_abstract'])) {
    if (isset($_SESSION['is_page_valid'])) {
      $is_abstract_valid = true;

      $error_msg = '';
      if (strcmp(trim($_POST['abstract_title']), "") == 0)  {
        $error_msg = $error_msg . '請填寫題目<br />';
        $is_abstract_valid = false;
      }
      else {
        if (mb_strlen(trim($_POST['abstract_title']), 'UTF-8')  == 1) {
          $error_msg = $error_msg . '題目不合法<br />';
          $is_abstract_valid = false;
        }
      }
      if (strcmp(trim($_POST['first_author_name']), "") == 0)  {
        $error_msg = $error_msg . '請填寫第一作者<br />';
        $is_abstract_valid = false;
      }
      else {
        if (mb_strlen(trim($_POST['first_author_name']), 'UTF-8')  == 1) {
          $error_msg = $error_msg . '第一作者不合法<br />';
          $is_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['first_author_affiliation']), "") == 0)  {
            $error_msg = $error_msg . '請填寫第一作者所屬單位<br />';
            $is_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['first_author_affiliation']), 'UTF-8')  == 1) {
              $error_msg = $error_msg . '第一作者所屬單位不合法<br />';
              $is_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['second_author_name']), "") != 0)  {
        if (mb_strlen(trim($_POST['second_author_name']), 'UTF-8')  == 1) {
          $error_msg = $error_msg . '第二作者不合法<br />';
          $is_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['second_author_affiliation']), "") == 0)  {
            $error_msg = $error_msg . '請填寫第二作者所屬單位<br />';
            $is_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['second_author_affiliation']), 'UTF-8')  == 1) {
              $error_msg = $error_msg . '第二作者所屬單位不合法<br />';
              $is_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['second_author_affiliation']), "") != 0) {
        if (mb_strlen(trim($_POST['second_author_affiliation']), 'UTF-8')  == 1) {
          $error_msg = $error_msg . '第二作者所屬單位不合法<br />';
          $is_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['second_author_name']), "") == 0)  {
            $error_msg = $error_msg . '請填寫第二作者<br />';
            $is_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['second_author_name']), 'UTF-8')  == 1) {
              $error_msg = $error_msg . '第二作者不合法<br />';
              $is_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['third_author_name']), "") != 0)  {
        if (mb_strlen(trim($_POST['third_author_name']), 'UTF-8')  == 1) {
          $error_msg = $error_msg . '第三作者不合法<br />';
          $is_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['third_author_affiliation']), "") == 0)  {
            $error_msg = $error_msg . '請填寫第三作者所屬單位<br />';
            $is_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['third_author_affiliation']), 'UTF-8')  == 1) {
              $error_msg = $error_msg . '第三作者所屬單位不合法<br />';
              $is_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['third_author_affiliation']), "") != 0) {
        if (mb_strlen(trim($_POST['third_author_affiliation']), 'UTF-8')  == 1) {
          $error_msg = $error_msg . '第三作者所屬單位不合法<br />';
          $is_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['third_author_name']), "") == 0)  {
            $error_msg = $error_msg . '請填寫第三作者<br />';
            $is_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['third_author_name']), 'UTF-8')  == 1) {
              $error_msg = $error_msg . '第三作者不合法<br />';
              $is_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['fourth_author_name']), "") != 0)  {
        if (mb_strlen(trim($_POST['fourth_author_name']), 'UTF-8')  == 1) {
          $error_msg = $error_msg . '第四作者不合法<br />';
          $is_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['fourth_author_affiliation']), "") == 0)  {
            $error_msg = $error_msg . '請填寫第四作者所屬單位<br />';
            $is_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['fourth_author_affiliation']), 'UTF-8')  == 1) {
              $error_msg = $error_msg . '第四作者所屬單位不合法<br />';
              $is_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['fourth_author_affiliation']), "") != 0) {
        if (mb_strlen(trim($_POST['fourth_author_affiliation']), 'UTF-8')  == 1) {
          $error_msg = $error_msg . '第四作者所屬單位不合法<br />';
          $is_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['fourth_author_name']), "") == 0)  {
            $error_msg = $error_msg . '請填寫第四作者<br />';
            $is_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['fourth_author_name']), 'UTF-8')  == 1) {
              $error_msg = $error_msg . '第四作者不合法<br />';
              $is_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['fifth_author_name']), "") != 0)  {
        if (mb_strlen(trim($_POST['fifth_author_name']), 'UTF-8')  == 1) {
          $error_msg = $error_msg . '第五作者不合法<br />';
          $is_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['fifth_author_affiliation']), "") == 0)  {
            $error_msg = $error_msg . '請填寫第五作者所屬單位<br />';
            $is_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['fifth_author_affiliation']), 'UTF-8')  == 1) {
              $error_msg = $error_msg . '第五作者所屬單位不合法<br />';
              $is_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['fifth_author_affiliation']), "") != 0) {
        if (mb_strlen(trim($_POST['fifth_author_affiliation']), 'UTF-8')  == 1) {
          $error_msg = $error_msg . '第五作者所屬單位不合法<br />';
          $is_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['fifth_author_name']), "") == 0)  {
            $error_msg = $error_msg . '請填寫第五作者<br />';
            $is_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['fifth_author_name']), 'UTF-8')  == 1) {
              $error_msg = $error_msg . '第五作者不合法<br />';
              $is_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['sixth_author_name']), "") != 0)  {
        if (mb_strlen(trim($_POST['sixth_author_name']), 'UTF-8')  == 1) {
          $error_msg = $error_msg . '第六作者不合法<br />';
          $is_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['sixth_author_affiliation']), "") == 0)  {
            $error_msg = $error_msg . '請填寫第六作者所屬單位<br />';
            $is_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['sixth_author_affiliation']), 'UTF-8')  == 1) {
              $error_msg = $error_msg . '第六作者所屬單位不合法<br />';
              $is_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['sixth_author_affiliation']), "") != 0) {
        if (mb_strlen(trim($_POST['sixth_author_affiliation']), 'UTF-8')  == 1) {
          $error_msg = $error_msg . '第六作者所屬單位不合法<br />';
          $is_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['sixth_author_name']), "") == 0)  {
            $error_msg = $error_msg . '請填寫第六作者<br />';
            $is_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['sixth_author_name']), 'UTF-8')  == 1) {
              $error_msg = $error_msg . '第六作者不合法<br />';
              $is_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['seventh_author_name']), "") != 0)  {
        if (mb_strlen(trim($_POST['seventh_author_name']), 'UTF-8')  == 1) {
          $error_msg = $error_msg . '第七作者不合法<br />';
          $is_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['seventh_author_affiliation']), "") == 0)  {
            $error_msg = $error_msg . '請填寫第七作者所屬單位<br />';
            $is_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['seventh_author_affiliation']), 'UTF-8')  == 1) {
              $error_msg = $error_msg . '第七作者所屬單位不合法<br />';
              $is_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['seventh_author_affiliation']), "") != 0) {
        if (mb_strlen(trim($_POST['seventh_author_affiliation']), 'UTF-8')  == 1) {
          $error_msg = $error_msg . '第七作者所屬單位不合法<br />';
          $is_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['seventh_author_name']), "") == 0)  {
            $error_msg = $error_msg . '請填寫第七作者<br />';
            $is_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['seventh_author_name']), 'UTF-8')  == 1) {
              $error_msg = $error_msg . '第七作者不合法<br />';
              $is_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['eighth_author_name']), "") != 0)  {
        if (mb_strlen(trim($_POST['eighth_author_name']), 'UTF-8')  == 1) {
          $error_msg = $error_msg . '第八作者不合法<br />';
          $is_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['eighth_author_affiliation']), "") == 0)  {
            $error_msg = $error_msg . '請填寫第八作者所屬單位<br />';
            $is_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['eighth_author_affiliation']), 'UTF-8')  == 1) {
              $error_msg = $error_msg . '第八作者所屬單位不合法<br />';
              $is_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['eighth_author_affiliation']), "") != 0) {
        if (mb_strlen(trim($_POST['eighth_author_affiliation']), 'UTF-8')  == 1) {
          $error_msg = $error_msg . '第八作者所屬單位不合法<br />';
          $is_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['eighth_author_name']), "") == 0)  {
            $error_msg = $error_msg . '請填寫第八作者<br />';
            $is_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['eighth_author_name']), 'UTF-8')  == 1) {
              $error_msg = $error_msg . '第八作者不合法<br />';
              $is_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['ninth_author_name']), "") != 0)  {
        if (mb_strlen(trim($_POST['ninth_author_name']), 'UTF-8')  == 1) {
          $error_msg = $error_msg . '第九作者不合法<br />';
          $is_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['ninth_author_affiliation']), "") == 0)  {
            $error_msg = $error_msg . '請填寫第九作者所屬單位<br />';
            $is_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['ninth_author_affiliation']), 'UTF-8')  == 1) {
              $error_msg = $error_msg . '第九作者所屬單位不合法<br />';
              $is_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['ninth_author_affiliation']), "") != 0) {
        if (mb_strlen(trim($_POST['ninth_author_affiliation']), 'UTF-8')  == 1) {
          $error_msg = $error_msg . '第九作者所屬單位不合法<br />';
          $is_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['ninth_author_name']), "") == 0)  {
            $error_msg = $error_msg . '請填寫第九作者<br />';
            $is_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['ninth_author_name']), 'UTF-8')  == 1) {
              $error_msg = $error_msg . '第九作者不合法<br />';
              $is_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['abstract']), "") == 0)  {
        $error_msg = $error_msg . '請填寫摘要<br />';
        $is_abstract_valid = false;
      }
      if (strcmp(trim($_POST['keywords']), "") == 0)  {
        $error_msg = $error_msg . '請填寫關鍵字<br />';
        $is_abstract_valid = false;
      }
      else {
        if (mb_strlen(trim($_POST['keywords']), 'UTF-8')  == 1) {
          $error_msg = $error_msg . '關鍵字不合法<br />';
          $is_abstract_valid = false;
        }
      }

      if ($is_abstract_valid) {
        if (isset($_POST['username']) && isset($_POST['email']) && isset($_POST['abstract_title'])) {
          $username = trim($_POST['username']);
          $email = trim($_POST['email']);
          $abstract_title = trim($_POST['abstract_title']);
          $query = sprintf("SELECT * FROM submission WHERE username='%s' AND email='%s' AND abstract_title='%s'",
            mysql_real_escape_string($username),
            mysql_real_escape_string($email),
            mysql_real_escape_string($abstract_title)
          );
          $sql_sub_check = $db->sql_query($query);
          $sub_check = $db->sql_numrows($sql_sub_check);

          if ($sub_check == 0) {
            $equipment = $_SESSION['equipment'];
            if (is_null($equipment)) {
              $selected_equipment = '';
            }
            else {
              $selected_equipment = implode(",", $equipment);
            }
            $_SESSION['equipment'] = $selected_equipment;
            $_SESSION['abstract_title'] = trim($_POST['abstract_title']);

            $abstract_author_names = '';
            if (strcmp(trim($_POST['first_author_name']), "") != 0) {
              $abstract_author_names = $abstract_author_names . trim($_POST['first_author_name']) . '@@';
            }
            if (strcmp(trim($_POST['second_author_name']), "") != 0) {
              $abstract_author_names = $abstract_author_names . trim($_POST['second_author_name']) . '@@';
            }
            if (strcmp(trim($_POST['third_author_name']), "") != 0) {
              $abstract_author_names = $abstract_author_names . trim($_POST['third_author_name']) . '@@';
            }
            if (strcmp(trim($_POST['fourth_author_name']), "") != 0) {
              $abstract_author_names = $abstract_author_names . trim($_POST['fourth_author_name']) . '@@';
            }
            if (strcmp(trim($_POST['fifth_author_name']), "") != 0) {
              $abstract_author_names = $abstract_author_names . trim($_POST['fifth_author_name']) . '@@';
            }
            if (strcmp(trim($_POST['sixth_author_name']), "") != 0) {
              $abstract_author_names = $abstract_author_names . trim($_POST['sixth_author_name']) . '@@';
            }
            if (strcmp(trim($_POST['seventh_author_name']), "") != 0) {
              $abstract_author_names = $abstract_author_names . trim($_POST['seventh_author_name']) . '@@';
            }
            if (strcmp(trim($_POST['eighth_author_name']), "") != 0) {
              $abstract_author_names = $abstract_author_names . trim($_POST['eighth_author_name']) . '@@';
            }
            if (strcmp(trim($_POST['ninth_author_name']), "") != 0) {
              $abstract_author_names = $abstract_author_names . trim($_POST['ninth_author_name']) . '@@';
            }
            $_SESSION['abstract_author_names'] = substr($abstract_author_names, 0, -2);

            $abstract_author_affiliations = '';
            if (strcmp(trim($_POST['first_author_affiliation']), "") != 0) {
              $abstract_author_affiliations = $abstract_author_affiliations . trim($_POST['first_author_affiliation']) . '@@';
            }
            if (strcmp(trim($_POST['second_author_affiliation']), "") != 0) {
              $abstract_author_affiliations = $abstract_author_affiliations . trim($_POST['second_author_affiliation']) . '@@';
            }
            if (strcmp(trim($_POST['third_author_affiliation']), "") != 0) {
              $abstract_author_affiliations = $abstract_author_affiliations . trim($_POST['third_author_affiliation']) . '@@';
            }
            if (strcmp(trim($_POST['fourth_author_affiliation']), "") != 0) {
              $abstract_author_affiliations = $abstract_author_affiliations . trim($_POST['fourth_author_affiliation']) . '@@';
            }
            if (strcmp(trim($_POST['fifth_author_affiliation']), "") != 0) {
              $abstract_author_affiliations = $abstract_author_affiliations . trim($_POST['fifth_author_affiliation']) . '@@';
            }
            if (strcmp(trim($_POST['sixth_author_affiliation']), "") != 0) {
              $abstract_author_affiliations = $abstract_author_affiliations . trim($_POST['sixth_author_affiliation']) . '@@';
            }
            if (strcmp(trim($_POST['seventh_author_affiliation']), "") != 0) {
              $abstract_author_affiliations = $abstract_author_affiliations . trim($_POST['seventh_author_affiliation']) . '@@';
            }
            if (strcmp(trim($_POST['eighth_author_affiliation']), "") != 0) {
              $abstract_author_affiliations = $abstract_author_affiliations . trim($_POST['eighth_author_affiliation']) . '@@';
            }
            if (strcmp(trim($_POST['ninth_author_affiliation']), "") != 0) {
              $abstract_author_affiliations = $abstract_author_affiliations . trim($_POST['ninth_author_affiliation']) . '@@';
            }
            $_SESSION['abstract_author_affiliations'] = substr($abstract_author_affiliations, 0, -2);

            $_SESSION['abstract'] = trim($_POST['abstract']);
            $_SESSION['abstract_keywords'] = trim($_POST['keywords']);

            $_SESSION['symposium_titles'] = '';
            $_SESSION['symposium_author_names'] = '';
            $_SESSION['symposium_author_affiliations'] = '';
            $_SESSION['symposium_keywords'] = '';
            $_SESSION['symposium_abstracts'] = '';

            $query = sprintf("INSERT INTO `submission`(username, affiliation, title, telephone, email, division, other_division, presentation_type, equipment, other_equipment,
                              abstract_title, abstract_author_names, abstract_author_affiliations, abstract_keywords, abstract,
                              symposium_titles, symposium_author_names, symposium_author_affiliations, symposium_keywords, symposium_abstracts,
                              regdate, ipaddress)
                              VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', ('%s'), '%s',
                                      '%s', '%s', '%s', '%s', '%s',
                                      '%s', '%s', '%s', '%s', '%s',
                                      NOW(), '%s');",
                              mysql_real_escape_string($_SESSION['username']),
                              mysql_real_escape_string($_SESSION['affiliation']),
                              mysql_real_escape_string($_SESSION['title']),
                              mysql_real_escape_string($_SESSION['telephone']),
                              mysql_real_escape_string($_SESSION['email']),
                              mysql_real_escape_string($_SESSION['division']),
                              mysql_real_escape_string($_SESSION['other_division']),
                              mysql_real_escape_string($_SESSION['presentation_type']),
                              mysql_real_escape_string($_SESSION['equipment']),
                              mysql_real_escape_string($_SESSION['other_equipment']),
                              mysql_real_escape_string($_SESSION['abstract_title']),
                              mysql_real_escape_string($_SESSION['abstract_author_names']),
                              mysql_real_escape_string($_SESSION['abstract_author_affiliations']),
                              mysql_real_escape_string($_SESSION['abstract_keywords']),
                              mysql_real_escape_string($_SESSION['abstract']),
                              mysql_real_escape_string($_SESSION['symposium_titles']),
                              mysql_real_escape_string($_SESSION['symposium_author_names']),
                              mysql_real_escape_string($_SESSION['symposium_author_affiliations']),
                              mysql_real_escape_string($_SESSION['symposium_keywords']),
                              mysql_real_escape_string($_SESSION['symposium_abstracts']),
                              mysql_real_escape_string($_SERVER['REMOTE_ADDR'])
                            );
            $db->sql_query($query);
            $query = sprintf("SELECT * FROM submission WHERE username='%s' AND email='%s' AND abstract_title='%s'",
              mysql_real_escape_string($_SESSION['username']),
              mysql_real_escape_string($_SESSION['email']),
              mysql_real_escape_string($_SESSION['abstract_title'])
            );
            $sql_sub_check = $db->sql_query($query);
            $sub_check = $db->sql_numrows($sql_sub_check);

            if ($sub_check != 0) {
              include("$ROOT_DIR/class.phpmailer.php");

              $mail = new PHPMailer();

              $mail->IsSMTP();
              $mail->SMTPAuth   = true;                   // enable SMTP authentication
              $mail->SMTPSecure = "ssl";                  // sets the prefix to the servier
              $mail->Host       = "smtp.gmail.com";       // sets GMAIL as the SMTP server
              $mail->Port       = 465;                    // set the SMTP port for the GMAIL server
              $mail->Username   = "";                     // GMAIL username
              $mail->Password   = "";                     // GMAIL password
              $mail->CharSet    = "utf8";

              $mail->SetFrom("b93102063@ntu.edu.tw", "第四十八屆台灣心理學年會");
              $mail->AddReplyTo("b93102063@ntu.edu.tw", "第四十八屆台灣心理學年會");
              $mail->AddAddress($_SESSION['email'], $_SESSION['username']);
              $mail->Subject  = "第四十八屆台灣心理學年會投稿確認信";

              $body = sprintf("%s 您好：\n\n感謝您的投稿，若您有任何疑問，十分歡迎您來信詢問，電子郵件地址：b93102063@ntu.edu.tw。\n\nThank you very much for your on-line registration. If any question, you are very much welcome to contact us on b93102063@ntu.edu.tw.\n\n\n第四十八屆台灣心理學年會", $_SESSION['username']);
              $mail->Body = $body;

              if (!$mail->Send()) {
                $_SESSION['error_msg'] = $mail->ErrorInfo;
                header("Location: failure.php");
              } else {
                header("Location: success.php");
              }
            }
            else {
              $_SESSION['error_msg'] = '系統錯誤，投稿失敗！';
              header("Location: failure.php");
            }
          }
          else {
            $row = $db->sql_fetchrow($sql_sub_check);
            $_SESSION['username'] = $row['username'];
            $_SESSION['email'] = $row['email'];
            $_SESSION['regdate'] = $row['regdate'];
            $_SESSION['abstract_title'] = $row['abstract_title'];
            header("Location: duplicate.php");
          }
        }
        else {
          session_unset();
          session_destroy();
          exit("操作不允許！");
        }
      }
      else {
        if (strcmp(trim($_POST['abstract_title']), "") != 0) {
          $_SESSION['abstract_title'] = trim($_POST['abstract_title']);
        }
        else {
          $_SESSION['abstract_title'] = '';
        }
        if (strcmp(trim($_POST['first_author_name']), "") != 0) {
          $_SESSION['first_author_name'] = trim($_POST['first_author_name']);
        }
        else {
          $_SESSION['first_author_name'] = '';
        }
        if (strcmp(trim($_POST['first_author_affiliation']), "") != 0) {
          $_SESSION['first_author_affiliation'] = trim($_POST['first_author_affiliation']);
        }
        else {
          $_SESSION['first_author_affiliation'] = '';
        }
        if (strcmp(trim($_POST['second_author_name']), "") != 0) {
          $_SESSION['second_author_name'] = trim($_POST['second_author_name']);
        }
        else {
          $_SESSION['second_author_name'] = '';
        }
        if (strcmp(trim($_POST['second_author_affiliation']), "") != 0) {
          $_SESSION['second_author_affiliation'] = trim($_POST['second_author_affiliation']);
        }
        else {
          $_SESSION['second_author_affiliation'] = '';
        }
        if (strcmp(trim($_POST['third_author_name']), "") != 0) {
          $_SESSION['third_author_name'] = trim($_POST['third_author_name']);
        }
        else {
          $_SESSION['third_author_name'] = '';
        }
        if (strcmp(trim($_POST['third_author_affiliation']), "") != 0) {
          $_SESSION['third_author_affiliation'] = trim($_POST['third_author_affiliation']);
        }
        else {
          $_SESSION['third_author_affiliation'] = '';
        }
        if (strcmp(trim($_POST['fourth_author_name']), "") != 0) {
          $_SESSION['fourth_author_name'] = trim($_POST['fourth_author_name']);
        }
        else {
          $_SESSION['fourth_author_name'] = '';
        }
        if (strcmp(trim($_POST['fourth_author_affiliation']), "") != 0) {
          $_SESSION['fourth_author_affiliation'] = trim($_POST['fourth_author_affiliation']);
        }
        else {
          $_SESSION['fourth_author_affiliation'] = '';
        }
        if (strcmp(trim($_POST['fifth_author_name']), "") != 0) {
          $_SESSION['fifth_author_name'] = trim($_POST['fifth_author_name']);
        }
        else {
          $_SESSION['fifth_author_name'] = '';
        }
        if (strcmp(trim($_POST['fifth_author_affiliation']), "") != 0) {
          $_SESSION['fifth_author_affiliation'] = trim($_POST['fifth_author_affiliation']);
        }
        else {
          $_SESSION['fifth_author_affiliation'] = '';
        }
        if (strcmp(trim($_POST['sixth_author_name']), "") != 0) {
          $_SESSION['sixth_author_name'] = trim($_POST['sixth_author_name']);
        }
        else {
           $_SESSION['sixth_author_name'] = '';
        }
        if (strcmp(trim($_POST['sixth_author_affiliation']), "") != 0) {
          $_SESSION['sixth_author_affiliation'] = trim($_POST['sixth_author_affiliation']);
        }
        else {
          $_SESSION['sixth_author_affiliation'] = '';
        }
        if (strcmp(trim($_POST['seventh_author_name']), "") != 0) {
          $_SESSION['seventh_author_name'] = trim($_POST['seventh_author_name']);
        }
        else {
          $_SESSION['seventh_author_name'] = '';
        }
        if (strcmp(trim($_POST['seventh_author_affiliation']), "") != 0) {
          $_SESSION['seventh_author_affiliation'] = trim($_POST['seventh_author_affiliation']);
        }
        else {
          $_SESSION['seventh_author_affiliation'] = '';
        }
        if (strcmp(trim($_POST['eighth_author_name']), "") != 0) {
          $_SESSION['eighth_author_name'] = trim($_POST['eighth_author_name']);
        }
        else {
          $_SESSION['eighth_author_name'] = '';
        }
        if (strcmp(trim($_POST['eighth_author_affiliation']), "") != 0) {
          $_SESSION['eighth_author_affiliation'] = trim($_POST['eighth_author_affiliation']);
        }
        else {
          $_SESSION['eighth_author_affiliation'] = '';
        }
        if (strcmp(trim($_POST['ninth_author_name']), "") != 0) {
          $_SESSION['ninth_author_name'] = trim($_POST['ninth_author_name']);
        }
        else {
          $_SESSION['ninth_author_name'] = '';
        }
        if (strcmp(trim($_POST['ninth_author_affiliation']), "") != 0) {
          $_SESSION['ninth_author_affiliation'] = trim($_POST['ninth_author_affiliation']);
        }
        else {
          $_SESSION['ninth_author_affiliation'] = '';
        }
        if (strcmp(trim($_POST['abstract']), "") != 0) {
          $_SESSION['abstract'] = trim($_POST['abstract']);
        }
        else {
          $_SESSION['abstract'] = '';
        }
        if (strcmp(trim($_POST['keywords']), "") != 0) {
          $_SESSION['keywords'] = trim($_POST['keywords']);
        }
        else {
          $_SESSION['keywords'] = '';
        }

        $_SESSION['abstract_error_msg'] = $error_msg;

        header("Location: submit.php");
      }
    }
  }

  if (isset($_POST['next_abstract'])) {
    if (isset($_SESSION['is_page_valid'])) {
      $is_symposium_abstract_valid = true;

      $symposium_error_msg = '';
      if (strcmp(trim($_POST['symposium_abstract_title']), "") == 0)  {
        $symposium_error_msg = $symposium_error_msg . '請填寫題目<br />';
        $is_symposium_abstract_valid = false;
      }
      else {
        if (mb_strlen(trim($_POST['symposium_abstract_title']), 'UTF-8')  == 1) {
          $symposium_error_msg = $symposium_error_msg . '題目不合法<br />';
          $is_symposium_abstract_valid = false;
        }
      }
      if (strcmp(trim($_POST['symposium_first_author_name']), "") == 0)  {
        $symposium_error_msg = $symposium_error_msg . '請填寫第一作者<br />';
        $is_symposium_abstract_valid = false;
      }
      else {
        if (mb_strlen(trim($_POST['symposium_first_author_name']), 'UTF-8')  == 1) {
          $symposium_error_msg = $symposium_error_msg . '第一作者不合法<br />';
          $is_symposium_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['symposium_first_author_affiliation']), "") == 0)  {
            $symposium_error_msg = $symposium_error_msg . '請填寫第一作者所屬單位<br />';
            $is_symposium_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['symposium_first_author_affiliation']), 'UTF-8')  == 1) {
              $symposium_error_msg = $symposium_error_msg . '第一作者所屬單位不合法<br />';
              $is_symposium_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['symposium_second_author_name']), "") != 0)  {
        if (mb_strlen(trim($_POST['symposium_second_author_name']), 'UTF-8')  == 1) {
          $symposium_error_msg = $symposium_error_msg . '第二作者不合法<br />';
          $is_symposium_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['symposium_second_author_affiliation']), "") == 0)  {
            $symposium_error_msg = $symposium_error_msg . '請填寫第二作者所屬單位<br />';
            $is_symposium_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['symposium_second_author_affiliation']), 'UTF-8')  == 1) {
              $symposium_error_msg = $symposium_error_msg . '第二作者所屬單位不合法<br />';
              $is_symposium_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['symposium_second_author_affiliation']), "") != 0) {
        if (mb_strlen(trim($_POST['symposium_second_author_affiliation']), 'UTF-8')  == 1) {
          $symposium_error_msg = $symposium_error_msg . '第二作者所屬單位不合法<br />';
          $is_symposium_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['symposium_second_author_name']), "") == 0)  {
            $symposium_error_msg = $symposium_error_msg . '請填寫第二作者<br />';
            $is_symposium_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['symposium_second_author_name']), 'UTF-8')  == 1) {
              $symposium_error_msg = $symposium_error_msg . '第二作者不合法<br />';
              $is_symposium_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['symposium_third_author_name']), "") != 0)  {
        if (mb_strlen(trim($_POST['symposium_third_author_name']), 'UTF-8')  == 1) {
          $symposium_error_msg = $symposium_error_msg . '第三作者不合法<br />';
          $is_symposium_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['symposium_third_author_affiliation']), "") == 0)  {
            $symposium_error_msg = $symposium_error_msg . '請填寫第三作者所屬單位<br />';
            $is_symposium_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['symposium_third_author_affiliation']), 'UTF-8')  == 1) {
              $symposium_error_msg = $symposium_error_msg . '第三作者所屬單位不合法<br />';
              $is_symposium_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['symposium_third_author_affiliation']), "") != 0) {
        if (mb_strlen(trim($_POST['symposium_third_author_affiliation']), 'UTF-8')  == 1) {
          $symposium_error_msg = $symposium_error_msg . '第三作者所屬單位不合法<br />';
          $is_symposium_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['symposium_third_author_name']), "") == 0)  {
            $symposium_error_msg = $symposium_error_msg . '請填寫第三作者<br />';
            $is_symposium_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['symposium_third_author_name']), 'UTF-8')  == 1) {
              $symposium_error_msg = $symposium_error_msg . '第三作者不合法<br />';
              $is_symposium_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['symposium_fourth_author_name']), "") != 0)  {
        if (mb_strlen(trim($_POST['symposium_fourth_author_name']), 'UTF-8')  == 1) {
          $symposium_error_msg = $symposium_error_msg . '第四作者不合法<br />';
          $is_symposium_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['symposium_fourth_author_affiliation']), "") == 0)  {
            $symposium_error_msg = $symposium_error_msg . '請填寫第四作者所屬單位<br />';
            $is_symposium_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['symposium_fourth_author_affiliation']), 'UTF-8')  == 1) {
              $symposium_error_msg = $symposium_error_msg . '第四作者所屬單位不合法<br />';
              $is_symposium_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['symposium_fourth_author_affiliation']), "") != 0) {
        if (mb_strlen(trim($_POST['symposium_fourth_author_affiliation']), 'UTF-8')  == 1) {
          $symposium_error_msg = $symposium_error_msg . '第四作者所屬單位不合法<br />';
          $is_symposium_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['symposium_fourth_author_name']), "") == 0)  {
            $symposium_error_msg = $symposium_error_msg . '請填寫第四作者<br />';
            $is_symposium_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['symposium_fourth_author_name']), 'UTF-8')  == 1) {
              $symposium_error_msg = $symposium_error_msg . '第四作者不合法<br />';
              $is_symposium_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['symposium_fifth_author_name']), "") != 0)  {
        if (mb_strlen(trim($_POST['symposium_fifth_author_name']), 'UTF-8')  == 1) {
          $symposium_error_msg = $symposium_error_msg . '第五作者不合法<br />';
          $is_symposium_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['symposium_fifth_author_affiliation']), "") == 0)  {
            $symposium_error_msg = $symposium_error_msg . '請填寫第五作者所屬單位<br />';
            $is_symposium_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['symposium_fifth_author_affiliation']), 'UTF-8')  == 1) {
              $symposium_error_msg = $symposium_error_msg . '第五作者所屬單位不合法<br />';
              $is_symposium_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['symposium_fifth_author_affiliation']), "") != 0) {
        if (mb_strlen(trim($_POST['symposium_fifth_author_affiliation']), 'UTF-8')  == 1) {
          $symposium_error_msg = $symposium_error_msg . '第五作者所屬單位不合法<br />';
          $is_symposium_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['symposium_fifth_author_name']), "") == 0)  {
            $symposium_error_msg = $symposium_error_msg . '請填寫第五作者<br />';
            $is_symposium_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['symposium_fifth_author_name']), 'UTF-8')  == 1) {
              $symposium_error_msg = $symposium_error_msg . '第五作者不合法<br />';
              $is_symposium_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['symposium_sixth_author_name']), "") != 0)  {
        if (mb_strlen(trim($_POST['symposium_sixth_author_name']), 'UTF-8')  == 1) {
          $symposium_error_msg = $symposium_error_msg . '第六作者不合法<br />';
          $is_symposium_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['symposium_sixth_author_affiliation']), "") == 0)  {
            $symposium_error_msg = $symposium_error_msg . '請填寫第六作者所屬單位<br />';
            $is_symposium_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['symposium_sixth_author_affiliation']), 'UTF-8')  == 1) {
              $symposium_error_msg = $symposium_error_msg . '第六作者所屬單位不合法<br />';
              $is_symposium_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['symposium_sixth_author_affiliation']), "") != 0) {
        if (mb_strlen(trim($_POST['symposium_sixth_author_affiliation']), 'UTF-8')  == 1) {
          $symposium_error_msg = $symposium_error_msg . '第六作者所屬單位不合法<br />';
          $is_symposium_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['symposium_sixth_author_name']), "") == 0)  {
            $symposium_error_msg = $symposium_error_msg . '請填寫第六作者<br />';
            $is_symposium_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['symposium_sixth_author_name']), 'UTF-8')  == 1) {
              $symposium_error_msg = $symposium_error_msg . '第六作者不合法<br />';
              $is_symposium_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['symposium_seventh_author_name']), "") != 0)  {
        if (mb_strlen(trim($_POST['symposium_seventh_author_name']), 'UTF-8')  == 1) {
          $symposium_error_msg = $symposium_error_msg . '第七作者不合法<br />';
          $is_symposium_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['symposium_seventh_author_affiliation']), "") == 0)  {
            $symposium_error_msg = $symposium_error_msg . '請填寫第七作者所屬單位<br />';
            $is_symposium_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['symposium_seventh_author_affiliation']), 'UTF-8')  == 1) {
              $symposium_error_msg = $symposium_error_msg . '第七作者所屬單位不合法<br />';
              $is_symposium_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['symposium_seventh_author_affiliation']), "") != 0) {
        if (mb_strlen(trim($_POST['symposium_seventh_author_affiliation']), 'UTF-8')  == 1) {
          $symposium_error_msg = $symposium_error_msg . '第七作者所屬單位不合法<br />';
          $is_symposium_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['symposium_seventh_author_name']), "") == 0)  {
            $symposium_error_msg = $symposium_error_msg . '請填寫第七作者<br />';
            $is_symposium_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['symposium_seventh_author_name']), 'UTF-8')  == 1) {
              $symposium_error_msg = $symposium_error_msg . '第七作者不合法<br />';
              $is_symposium_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['symposium_eighth_author_name']), "") != 0)  {
        if (mb_strlen(trim($_POST['symposium_eighth_author_name']), 'UTF-8')  == 1) {
          $symposium_error_msg = $symposium_error_msg . '第八作者不合法<br />';
          $is_symposium_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['symposium_eighth_author_affiliation']), "") == 0)  {
            $symposium_error_msg = $symposium_error_msg . '請填寫第八作者所屬單位<br />';
            $is_symposium_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['symposium_eighth_author_affiliation']), 'UTF-8')  == 1) {
              $symposium_error_msg = $symposium_error_msg . '第八作者所屬單位不合法<br />';
              $is_symposium_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['symposium_eighth_author_affiliation']), "") != 0) {
        if (mb_strlen(trim($_POST['symposium_eighth_author_affiliation']), 'UTF-8')  == 1) {
          $symposium_error_msg = $symposium_error_msg . '第八作者所屬單位不合法<br />';
          $is_symposium_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['symposium_eighth_author_name']), "") == 0)  {
            $symposium_error_msg = $symposium_error_msg . '請填寫第八作者<br />';
            $is_symposium_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['symposium_eighth_author_name']), 'UTF-8')  == 1) {
              $symposium_error_msg = $symposium_error_msg . '第八作者不合法<br />';
              $is_symposium_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['symposium_ninth_author_name']), "") != 0)  {
        if (mb_strlen(trim($_POST['symposium_ninth_author_name']), 'UTF-8')  == 1) {
          $symposium_error_msg = $symposium_error_msg . '第九作者不合法<br />';
          $is_symposium_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['symposium_ninth_author_affiliation']), "") == 0)  {
            $symposium_error_msg = $symposium_error_msg . '請填寫第九作者所屬單位<br />';
            $is_symposium_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['symposium_ninth_author_affiliation']), 'UTF-8')  == 1) {
              $symposium_error_msg = $symposium_error_msg . '第九作者所屬單位不合法<br />';
              $is_symposium_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['symposium_ninth_author_affiliation']), "") != 0) {
        if (mb_strlen(trim($_POST['symposium_ninth_author_affiliation']), 'UTF-8')  == 1) {
          $symposium_error_msg = $symposium_error_msg . '第九作者所屬單位不合法<br />';
          $is_symposium_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['symposium_ninth_author_name']), "") == 0)  {
            $symposium_error_msg = $symposium_error_msg . '請填寫第九作者<br />';
            $is_symposium_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['symposium_ninth_author_name']), 'UTF-8')  == 1) {
              $symposium_error_msg = $symposium_error_msg . '第九作者不合法<br />';
              $is_symposium_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['symposium_abstract']), "") == 0)  {
        $symposium_error_msg = $symposium_error_msg . '請填寫摘要<br />';
        $is_symposium_abstract_valid = false;
      }
      if (strcmp(trim($_POST['symposium_keywords']), "") == 0)  {
        $symposium_error_msg = $symposium_error_msg . '請填寫關鍵字<br />';
        $is_symposium_abstract_valid = false;
      }
      else {
        if (mb_strlen(trim($_POST['symposium_keywords']), 'UTF-8')  == 1) {
          $symposium_error_msg = $symposium_error_msg . '關鍵字不合法<br />';
          $is_symposium_abstract_valid = false;
        }
      }

      if ($is_symposium_abstract_valid) {
        $_SESSION['symposium_abstract_title'] = trim($_POST['symposium_abstract_title']);

        $symposium_abstract_author_names = '';
        if (strcmp(trim($_POST['symposium_first_author_name']), "") != 0) {
          $symposium_abstract_author_names = $symposium_abstract_author_names . trim($_POST['symposium_first_author_name']) . '@@';
        }
        if (strcmp(trim($_POST['symposium_second_author_name']), "") != 0) {
          $symposium_abstract_author_names = $symposium_abstract_author_names . trim($_POST['symposium_second_author_name']) . '@@';
        }
        if (strcmp(trim($_POST['symposium_third_author_name']), "") != 0) {
          $symposium_abstract_author_names = $symposium_abstract_author_names . trim($_POST['symposium_third_author_name']) . '@@';
        }
        if (strcmp(trim($_POST['symposium_fourth_author_name']), "") != 0) {
          $symposium_abstract_author_names = $symposium_abstract_author_names . trim($_POST['symposium_fourth_author_name']) . '@@';
        }
        if (strcmp(trim($_POST['symposium_fifth_author_name']), "") != 0) {
          $symposium_abstract_author_names = $symposium_abstract_author_names . trim($_POST['symposium_fifth_author_name']) . '@@';
        }
        if (strcmp(trim($_POST['symposium_sixth_author_name']), "") != 0) {
          $symposium_abstract_author_names = $symposium_abstract_author_names . trim($_POST['symposium_sixth_author_name']) . '@@';
        }
        if (strcmp(trim($_POST['symposium_seventh_author_name']), "") != 0) {
          $symposium_abstract_author_names = $symposium_abstract_author_names . trim($_POST['symposium_seventh_author_name']) . '@@';
        }
        if (strcmp(trim($_POST['symposium_eighth_author_name']), "") != 0) {
          $symposium_abstract_author_names = $symposium_abstract_author_names . trim($_POST['symposium_eighth_author_name']) . '@@';
        }
        if (strcmp(trim($_POST['symposium_ninth_author_name']), "") != 0) {
          $symposium_abstract_author_names = $symposium_abstract_author_names . trim($_POST['symposium_ninth_author_name']) . '@@';
        }
        $_SESSION['symposium_abstract_author_names'] = substr($symposium_abstract_author_names, 0, -2);

        $symposium_abstract_author_affiliations = '';
        if (strcmp(trim($_POST['symposium_first_author_affiliation']), "") != 0) {
          $symposium_abstract_author_affiliations = $symposium_abstract_author_affiliations . trim($_POST['symposium_first_author_affiliation']) . '@@';
        }
        if (strcmp(trim($_POST['symposium_second_author_affiliation']), "") != 0) {
          $symposium_abstract_author_affiliations = $symposium_abstract_author_affiliations . trim($_POST['symposium_second_author_affiliation']) . '@@';
        }
        if (strcmp(trim($_POST['symposium_third_author_affiliation']), "") != 0) {
          $symposium_abstract_author_affiliations = $symposium_abstract_author_affiliations . trim($_POST['symposium_third_author_affiliation']) . '@@';
        }
        if (strcmp(trim($_POST['symposium_fourth_author_affiliation']), "") != 0) {
          $symposium_abstract_author_affiliations = $symposium_abstract_author_affiliations . trim($_POST['symposium_fourth_author_affiliation']) . '@@';
        }
        if (strcmp(trim($_POST['symposium_fifth_author_affiliation']), "") != 0) {
          $symposium_abstract_author_affiliations = $symposium_abstract_author_affiliations . trim($_POST['symposium_fifth_author_affiliation']) . '@@';
        }
        if (strcmp(trim($_POST['symposium_sixth_author_affiliation']), "") != 0) {
          $symposium_abstract_author_affiliations = $symposium_abstract_author_affiliations . trim($_POST['symposium_sixth_author_affiliation']) . '@@';
        }
        if (strcmp(trim($_POST['symposium_seventh_author_affiliation']), "") != 0) {
          $symposium_abstract_author_affiliations = $symposium_abstract_author_affiliations . trim($_POST['symposium_seventh_author_affiliation']) . '@@';
        }
        if (strcmp(trim($_POST['symposium_eighth_author_affiliation']), "") != 0) {
          $symposium_abstract_author_affiliations = $symposium_abstract_author_affiliations . trim($_POST['symposium_eighth_author_affiliation']) . '@@';
        }
        if (strcmp(trim($_POST['symposium_ninth_author_affiliation']), "") != 0) {
          $symposium_abstract_author_affiliations = $symposium_abstract_author_affiliations . trim($_POST['symposium_ninth_author_affiliation']) . '@@';
        }
        $_SESSION['symposium_abstract_author_affiliations'] = substr($symposium_abstract_author_affiliations, 0, -2);

        $_SESSION['symposium_abstract'] = trim($_POST['symposium_abstract']);
        $_SESSION['symposium_keywords'] = trim($_POST['symposium_keywords']);

        $column_name = array('symposium_abstract_title', 'symposium_abstract_author_names', 'symposium_abstract_author_affiliations', 'symposium_abstract', 'symposium_keywords');
        $column_data = array($_SESSION['symposium_abstract_title'], $_SESSION['symposium_abstract_author_names'], $_SESSION['symposium_abstract_author_affiliations'], $_SESSION['symposium_abstract'], $_SESSION['symposium_keywords']);
        $symposium_tmp = array_combine($column_name, $column_data);

        if (isset($_SESSION['symposium_abstract_count'])) {
          $_SESSION['symposium_abstract_count'] = $_SESSION['symposium_abstract_count'] + 1;
        }
        else {
          $_SESSION['symposium_abstract_count'] = 0;
        }

        if (isset($_SESSION['symposium_tmp'])) {
          array_push($_SESSION['symposium_tmp'], $symposium_tmp);
        }
        else {
          $_SESSION['symposium_tmp'] = array();
          array_push($_SESSION['symposium_tmp'], $symposium_tmp);
        }

        unset($_SESSION['symposium_first_author_affiliation']);
        unset($_SESSION['symposium_first_author_name']);
        unset($_SESSION['symposium_second_author_affiliation']);
        unset($_SESSION['symposium_second_author_name']);
        unset($_SESSION['symposium_third_author_affiliation']);
        unset($_SESSION['symposium_third_author_name']);
        unset($_SESSION['symposium_fourth_author_affiliation']);
        unset($_SESSION['symposium_fourth_author_name']);
        unset($_SESSION['symposium_fifth_author_affiliation']);
        unset($_SESSION['symposium_fifth_author_name']);
        unset($_SESSION['symposium_sixth_author_affiliation']);
        unset($_SESSION['symposium_sixth_author_name']);
        unset($_SESSION['symposium_seventh_author_affiliation']);
        unset($_SESSION['symposium_seventh_author_name']);
        unset($_SESSION['symposium_eighth_author_affiliation']);
        unset($_SESSION['symposium_eighth_author_name']);
        unset($_SESSION['symposium_ninth_author_affiliation']);
        unset($_SESSION['symposium_ninth_author_name']);
        unset($_SESSION['symposium_abstract']);
        unset($_SESSION['symposium_keywords']);
        unset($_SESSION['symposium_abstract_title']);
        unset($_SESSION['symposium_error_msg']);

        header("Location: submit.php");
      }
      else {
        if (strcmp(trim($_POST['symposium_abstract_title']), "") != 0) {
          $_SESSION['symposium_abstract_title'] = trim($_POST['symposium_abstract_title']);
        }
        else {
          $_SESSION['symposium_abstract_title'] = '';
        }
        if (strcmp(trim($_POST['symposium_first_author_name']), "") != 0) {
          $_SESSION['symposium_first_author_name'] = trim($_POST['symposium_first_author_name']);
        }
        else {
          $_SESSION['symposium_first_author_name'] = '';
        }
        if (strcmp(trim($_POST['symposium_first_author_affiliation']), "") != 0) {
          $_SESSION['symposium_first_author_affiliation'] = trim($_POST['symposium_first_author_affiliation']);
        }
        else {
          $_SESSION['symposium_first_author_affiliation'] = '';
        }
        if (strcmp(trim($_POST['symposium_second_author_name']), "") != 0) {
          $_SESSION['symposium_second_author_name'] = trim($_POST['symposium_second_author_name']);
        }
        else {
          $_SESSION['symposium_second_author_name'] = '';
        }
        if (strcmp(trim($_POST['symposium_second_author_affiliation']), "") != 0) {
          $_SESSION['symposium_second_author_affiliation'] = trim($_POST['symposium_second_author_affiliation']);
        }
        else {
          $_SESSION['symposium_second_author_affiliation'] = '';
        }
        if (strcmp(trim($_POST['symposium_third_author_name']), "") != 0) {
          $_SESSION['symposium_third_author_name'] = trim($_POST['symposium_third_author_name']);
        }
        else {
          $_SESSION['symposium_third_author_name'] = '';
        }
        if (strcmp(trim($_POST['symposium_third_author_affiliation']), "") != 0) {
          $_SESSION['symposium_third_author_affiliation'] = trim($_POST['symposium_third_author_affiliation']);
        }
        else {
          $_SESSION['symposium_third_author_affiliation'] = '';
        }
        if (strcmp(trim($_POST['symposium_fourth_author_name']), "") != 0) {
          $_SESSION['symposium_fourth_author_name'] = trim($_POST['symposium_fourth_author_name']);
        }
        else {
          $_SESSION['symposium_fourth_author_name'] = '';
        }
        if (strcmp(trim($_POST['symposium_fourth_author_affiliation']), "") != 0) {
          $_SESSION['symposium_fourth_author_affiliation'] = trim($_POST['symposium_fourth_author_affiliation']);
        }
        else {
          $_SESSION['symposium_fourth_author_affiliation'] = '';
        }
        if (strcmp(trim($_POST['symposium_fifth_author_name']), "") != 0) {
          $_SESSION['symposium_fifth_author_name'] = trim($_POST['symposium_fifth_author_name']);
        }
        else {
          $_SESSION['symposium_fifth_author_name'] = '';
        }
        if (strcmp(trim($_POST['symposium_fifth_author_affiliation']), "") != 0) {
          $_SESSION['symposium_fifth_author_affiliation'] = trim($_POST['symposium_fifth_author_affiliation']);
        }
        else {
          $_SESSION['symposium_fifth_author_affiliation'] = '';
        }
        if (strcmp(trim($_POST['symposium_sixth_author_name']), "") != 0) {
          $_SESSION['symposium_sixth_author_name'] = trim($_POST['symposium_sixth_author_name']);
        }
        else {
           $_SESSION['symposium_sixth_author_name'] = '';
        }
        if (strcmp(trim($_POST['symposium_sixth_author_affiliation']), "") != 0) {
          $_SESSION['symposium_sixth_author_affiliation'] = trim($_POST['symposium_sixth_author_affiliation']);
        }
        else {
          $_SESSION['symposium_sixth_author_affiliation'] = '';
        }
        if (strcmp(trim($_POST['symposium_seventh_author_name']), "") != 0) {
          $_SESSION['symposium_seventh_author_name'] = trim($_POST['symposium_seventh_author_name']);
        }
        else {
          $_SESSION['symposium_seventh_author_name'] = '';
        }
        if (strcmp(trim($_POST['symposium_seventh_author_affiliation']), "") != 0) {
          $_SESSION['symposium_seventh_author_affiliation'] = trim($_POST['symposium_seventh_author_affiliation']);
        }
        else {
          $_SESSION['symposium_seventh_author_affiliation'] = '';
        }
        if (strcmp(trim($_POST['symposium_eighth_author_name']), "") != 0) {
          $_SESSION['symposium_eighth_author_name'] = trim($_POST['symposium_eighth_author_name']);
        }
        else {
          $_SESSION['symposium_eighth_author_name'] = '';
        }
        if (strcmp(trim($_POST['symposium_eighth_author_affiliation']), "") != 0) {
          $_SESSION['symposium_eighth_author_affiliation'] = trim($_POST['symposium_eighth_author_affiliation']);
        }
        else {
          $_SESSION['symposium_eighth_author_affiliation'] = '';
        }
        if (strcmp(trim($_POST['symposium_ninth_author_name']), "") != 0) {
          $_SESSION['symposium_ninth_author_name'] = trim($_POST['symposium_ninth_author_name']);
        }
        else {
          $_SESSION['symposium_ninth_author_name'] = '';
        }
        if (strcmp(trim($_POST['symposium_ninth_author_affiliation']), "") != 0) {
          $_SESSION['symposium_ninth_author_affiliation'] = trim($_POST['symposium_ninth_author_affiliation']);
        }
        else {
          $_SESSION['symposium_ninth_author_affiliation'] = '';
        }
        if (strcmp(trim($_POST['symposium_abstract']), "") != 0) {
          $_SESSION['symposium_abstract'] = trim($_POST['symposium_abstract']);
        }
        else {
          $_SESSION['symposium_abstract'] = '';
        }
        if (strcmp(trim($_POST['symposium_keywords']), "") != 0) {
          $_SESSION['symposium_keywords'] = trim($_POST['symposium_keywords']);
        }
        else {
          $_SESSION['symposium_keywords'] = '';
        }

        $_SESSION['symposium_error_msg'] = $symposium_error_msg;

        header("Location: submit.php");
      }
    }
  }

  if (isset($_POST['submit_total_abstract'])) {
    if (isset($_SESSION['is_page_valid'])) {
      $is_symposium_abstract_valid = true;

      $symposium_error_msg = '';
      if (strcmp(trim($_POST['symposium_abstract_title']), "") == 0)  {
        $symposium_error_msg = $symposium_error_msg . '請填寫題目<br />';
        $is_symposium_abstract_valid = false;
      }
      else {
        if (mb_strlen(trim($_POST['symposium_abstract_title']), 'UTF-8')  == 1) {
          $symposium_error_msg = $symposium_error_msg . '題目不合法<br />';
          $is_symposium_abstract_valid = false;
        }
      }
      if (strcmp(trim($_POST['symposium_first_author_name']), "") == 0)  {
        $symposium_error_msg = $symposium_error_msg . '請填寫第一作者<br />';
        $is_symposium_abstract_valid = false;
      }
      else {
        if (mb_strlen(trim($_POST['symposium_first_author_name']), 'UTF-8')  == 1) {
          $symposium_error_msg = $symposium_error_msg . '第一作者不合法<br />';
          $is_symposium_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['symposium_first_author_affiliation']), "") == 0)  {
            $symposium_error_msg = $symposium_error_msg . '請填寫第一作者所屬單位<br />';
            $is_symposium_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['symposium_first_author_affiliation']), 'UTF-8')  == 1) {
              $symposium_error_msg = $symposium_error_msg . '第一作者所屬單位不合法<br />';
              $is_symposium_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['symposium_second_author_name']), "") != 0)  {
        if (mb_strlen(trim($_POST['symposium_second_author_name']), 'UTF-8')  == 1) {
          $symposium_error_msg = $symposium_error_msg . '第二作者不合法<br />';
          $is_symposium_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['symposium_second_author_affiliation']), "") == 0)  {
            $symposium_error_msg = $symposium_error_msg . '請填寫第二作者所屬單位<br />';
            $is_symposium_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['symposium_second_author_affiliation']), 'UTF-8')  == 1) {
              $symposium_error_msg = $symposium_error_msg . '第二作者所屬單位不合法<br />';
              $is_symposium_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['symposium_second_author_affiliation']), "") != 0) {
        if (mb_strlen(trim($_POST['symposium_second_author_affiliation']), 'UTF-8')  == 1) {
          $symposium_error_msg = $symposium_error_msg . '第二作者所屬單位不合法<br />';
          $is_symposium_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['symposium_second_author_name']), "") == 0)  {
            $symposium_error_msg = $symposium_error_msg . '請填寫第二作者<br />';
            $is_symposium_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['symposium_second_author_name']), 'UTF-8')  == 1) {
              $symposium_error_msg = $symposium_error_msg . '第二作者不合法<br />';
              $is_symposium_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['symposium_third_author_name']), "") != 0)  {
        if (mb_strlen(trim($_POST['symposium_third_author_name']), 'UTF-8')  == 1) {
          $symposium_error_msg = $symposium_error_msg . '第三作者不合法<br />';
          $is_symposium_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['symposium_third_author_affiliation']), "") == 0)  {
            $symposium_error_msg = $symposium_error_msg . '請填寫第三作者所屬單位<br />';
            $is_symposium_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['symposium_third_author_affiliation']), 'UTF-8')  == 1) {
              $symposium_error_msg = $symposium_error_msg . '第三作者所屬單位不合法<br />';
              $is_symposium_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['symposium_third_author_affiliation']), "") != 0) {
        if (mb_strlen(trim($_POST['symposium_third_author_affiliation']), 'UTF-8')  == 1) {
          $symposium_error_msg = $symposium_error_msg . '第三作者所屬單位不合法<br />';
          $is_symposium_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['symposium_third_author_name']), "") == 0)  {
            $symposium_error_msg = $symposium_error_msg . '請填寫第三作者<br />';
            $is_symposium_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['symposium_third_author_name']), 'UTF-8')  == 1) {
              $symposium_error_msg = $symposium_error_msg . '第三作者不合法<br />';
              $is_symposium_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['symposium_fourth_author_name']), "") != 0)  {
        if (mb_strlen(trim($_POST['symposium_fourth_author_name']), 'UTF-8')  == 1) {
          $symposium_error_msg = $symposium_error_msg . '第四作者不合法<br />';
          $is_symposium_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['symposium_fourth_author_affiliation']), "") == 0)  {
            $symposium_error_msg = $symposium_error_msg . '請填寫第四作者所屬單位<br />';
            $is_symposium_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['symposium_fourth_author_affiliation']), 'UTF-8')  == 1) {
              $symposium_error_msg = $symposium_error_msg . '第四作者所屬單位不合法<br />';
              $is_symposium_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['symposium_fourth_author_affiliation']), "") != 0) {
        if (mb_strlen(trim($_POST['symposium_fourth_author_affiliation']), 'UTF-8')  == 1) {
          $symposium_error_msg = $symposium_error_msg . '第四作者所屬單位不合法<br />';
          $is_symposium_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['symposium_fourth_author_name']), "") == 0)  {
            $symposium_error_msg = $symposium_error_msg . '請填寫第四作者<br />';
            $is_symposium_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['symposium_fourth_author_name']), 'UTF-8')  == 1) {
              $symposium_error_msg = $symposium_error_msg . '第四作者不合法<br />';
              $is_symposium_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['symposium_fifth_author_name']), "") != 0)  {
        if (mb_strlen(trim($_POST['symposium_fifth_author_name']), 'UTF-8')  == 1) {
          $symposium_error_msg = $symposium_error_msg . '第五作者不合法<br />';
          $is_symposium_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['symposium_fifth_author_affiliation']), "") == 0)  {
            $symposium_error_msg = $symposium_error_msg . '請填寫第五作者所屬單位<br />';
            $is_symposium_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['symposium_fifth_author_affiliation']), 'UTF-8')  == 1) {
              $symposium_error_msg = $symposium_error_msg . '第五作者所屬單位不合法<br />';
              $is_symposium_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['symposium_fifth_author_affiliation']), "") != 0) {
        if (mb_strlen(trim($_POST['symposium_fifth_author_affiliation']), 'UTF-8')  == 1) {
          $symposium_error_msg = $symposium_error_msg . '第五作者所屬單位不合法<br />';
          $is_symposium_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['symposium_fifth_author_name']), "") == 0)  {
            $symposium_error_msg = $symposium_error_msg . '請填寫第五作者<br />';
            $is_symposium_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['symposium_fifth_author_name']), 'UTF-8')  == 1) {
              $symposium_error_msg = $symposium_error_msg . '第五作者不合法<br />';
              $is_symposium_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['symposium_sixth_author_name']), "") != 0)  {
        if (mb_strlen(trim($_POST['symposium_sixth_author_name']), 'UTF-8')  == 1) {
          $symposium_error_msg = $symposium_error_msg . '第六作者不合法<br />';
          $is_symposium_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['symposium_sixth_author_affiliation']), "") == 0)  {
            $symposium_error_msg = $symposium_error_msg . '請填寫第六作者所屬單位<br />';
            $is_symposium_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['symposium_sixth_author_affiliation']), 'UTF-8')  == 1) {
              $symposium_error_msg = $symposium_error_msg . '第六作者所屬單位不合法<br />';
              $is_symposium_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['symposium_sixth_author_affiliation']), "") != 0) {
        if (mb_strlen(trim($_POST['symposium_sixth_author_affiliation']), 'UTF-8')  == 1) {
          $symposium_error_msg = $symposium_error_msg . '第六作者所屬單位不合法<br />';
          $is_symposium_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['symposium_sixth_author_name']), "") == 0)  {
            $symposium_error_msg = $symposium_error_msg . '請填寫第六作者<br />';
            $is_symposium_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['symposium_sixth_author_name']), 'UTF-8')  == 1) {
              $symposium_error_msg = $symposium_error_msg . '第六作者不合法<br />';
              $is_symposium_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['symposium_seventh_author_name']), "") != 0)  {
        if (mb_strlen(trim($_POST['symposium_seventh_author_name']), 'UTF-8')  == 1) {
          $symposium_error_msg = $symposium_error_msg . '第七作者不合法<br />';
          $is_symposium_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['symposium_seventh_author_affiliation']), "") == 0)  {
            $symposium_error_msg = $symposium_error_msg . '請填寫第七作者所屬單位<br />';
            $is_symposium_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['symposium_seventh_author_affiliation']), 'UTF-8')  == 1) {
              $symposium_error_msg = $symposium_error_msg . '第七作者所屬單位不合法<br />';
              $is_symposium_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['symposium_seventh_author_affiliation']), "") != 0) {
        if (mb_strlen(trim($_POST['symposium_seventh_author_affiliation']), 'UTF-8')  == 1) {
          $symposium_error_msg = $symposium_error_msg . '第七作者所屬單位不合法<br />';
          $is_symposium_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['symposium_seventh_author_name']), "") == 0)  {
            $symposium_error_msg = $symposium_error_msg . '請填寫第七作者<br />';
            $is_symposium_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['symposium_seventh_author_name']), 'UTF-8')  == 1) {
              $symposium_error_msg = $symposium_error_msg . '第七作者不合法<br />';
              $is_symposium_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['symposium_eighth_author_name']), "") != 0)  {
        if (mb_strlen(trim($_POST['symposium_eighth_author_name']), 'UTF-8')  == 1) {
          $symposium_error_msg = $symposium_error_msg . '第八作者不合法<br />';
          $is_symposium_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['symposium_eighth_author_affiliation']), "") == 0)  {
            $symposium_error_msg = $symposium_error_msg . '請填寫第八作者所屬單位<br />';
            $is_symposium_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['symposium_eighth_author_affiliation']), 'UTF-8')  == 1) {
              $symposium_error_msg = $symposium_error_msg . '第八作者所屬單位不合法<br />';
              $is_symposium_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['symposium_eighth_author_affiliation']), "") != 0) {
        if (mb_strlen(trim($_POST['symposium_eighth_author_affiliation']), 'UTF-8')  == 1) {
          $symposium_error_msg = $symposium_error_msg . '第八作者所屬單位不合法<br />';
          $is_symposium_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['symposium_eighth_author_name']), "") == 0)  {
            $symposium_error_msg = $symposium_error_msg . '請填寫第八作者<br />';
            $is_symposium_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['symposium_eighth_author_name']), 'UTF-8')  == 1) {
              $symposium_error_msg = $symposium_error_msg . '第八作者不合法<br />';
              $is_symposium_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['symposium_ninth_author_name']), "") != 0)  {
        if (mb_strlen(trim($_POST['symposium_ninth_author_name']), 'UTF-8')  == 1) {
          $symposium_error_msg = $symposium_error_msg . '第九作者不合法<br />';
          $is_symposium_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['symposium_ninth_author_affiliation']), "") == 0)  {
            $symposium_error_msg = $symposium_error_msg . '請填寫第九作者所屬單位<br />';
            $is_symposium_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['symposium_ninth_author_affiliation']), 'UTF-8')  == 1) {
              $symposium_error_msg = $symposium_error_msg . '第九作者所屬單位不合法<br />';
              $is_symposium_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['symposium_ninth_author_affiliation']), "") != 0) {
        if (mb_strlen(trim($_POST['symposium_ninth_author_affiliation']), 'UTF-8')  == 1) {
          $symposium_error_msg = $symposium_error_msg . '第九作者所屬單位不合法<br />';
          $is_symposium_abstract_valid = false;
        }
        else {
          if (strcmp(trim($_POST['symposium_ninth_author_name']), "") == 0)  {
            $symposium_error_msg = $symposium_error_msg . '請填寫第九作者<br />';
            $is_symposium_abstract_valid = false;
          }
          else {
            if (mb_strlen(trim($_POST['symposium_ninth_author_name']), 'UTF-8')  == 1) {
              $symposium_error_msg = $symposium_error_msg . '第九作者不合法<br />';
              $is_symposium_abstract_valid = false;
            }
          }
        }
      }
      if (strcmp(trim($_POST['symposium_abstract']), "") == 0)  {
        $symposium_error_msg = $symposium_error_msg . '請填寫摘要<br />';
        $is_symposium_abstract_valid = false;
      }
      if (strcmp(trim($_POST['symposium_keywords']), "") == 0)  {
        $symposium_error_msg = $symposium_error_msg . '請填寫關鍵字<br />';
        $is_symposium_abstract_valid = false;
      }
      else {
        $is_abstract_empty = false;
        if (mb_strlen(trim($_POST['symposium_keywords']), 'UTF-8')  == 1) {
          $symposium_error_msg = $symposium_error_msg . '關鍵字不合法<br />';
          $is_symposium_abstract_valid = false;
        }
      }

      if ($is_symposium_abstract_valid) {
        $equipment = $_SESSION['equipment'];
        if (is_null($equipment)) {
          $selected_equipment = '';
        }
        else {
          $selected_equipment = implode(",", $equipment);
        }
        $_SESSION['equipment'] = $selected_equipment;

        $_SESSION['symposium_abstract_title'] = trim($_POST['symposium_abstract_title']);

        $symposium_abstract_author_names = '';
        if (strcmp(trim($_POST['symposium_first_author_name']), "") != 0) {
          $symposium_abstract_author_names = $symposium_abstract_author_names . trim($_POST['symposium_first_author_name']) . '@@';
        }
        if (strcmp(trim($_POST['symposium_second_author_name']), "") != 0) {
          $symposium_abstract_author_names = $symposium_abstract_author_names . trim($_POST['symposium_second_author_name']) . '@@';
        }
        if (strcmp(trim($_POST['symposium_third_author_name']), "") != 0) {
          $symposium_abstract_author_names = $symposium_abstract_author_names . trim($_POST['symposium_third_author_name']) . '@@';
        }
        if (strcmp(trim($_POST['symposium_fourth_author_name']), "") != 0) {
          $symposium_abstract_author_names = $symposium_abstract_author_names . trim($_POST['symposium_fourth_author_name']) . '@@';
        }
        if (strcmp(trim($_POST['symposium_fifth_author_name']), "") != 0) {
          $symposium_abstract_author_names = $symposium_abstract_author_names . trim($_POST['symposium_fifth_author_name']) . '@@';
        }
        if (strcmp(trim($_POST['symposium_sixth_author_name']), "") != 0) {
          $symposium_abstract_author_names = $symposium_abstract_author_names . trim($_POST['symposium_sixth_author_name']) . '@@';
        }
        if (strcmp(trim($_POST['symposium_seventh_author_name']), "") != 0) {
          $symposium_abstract_author_names = $symposium_abstract_author_names . trim($_POST['symposium_seventh_author_name']) . '@@';
        }
        if (strcmp(trim($_POST['symposium_eighth_author_name']), "") != 0) {
          $symposium_abstract_author_names = $symposium_abstract_author_names . trim($_POST['symposium_eighth_author_name']) . '@@';
        }
        if (strcmp(trim($_POST['symposium_ninth_author_name']), "") != 0) {
          $symposium_abstract_author_names = $symposium_abstract_author_names . trim($_POST['symposium_ninth_author_name']) . '@@';
        }
        $_SESSION['symposium_abstract_author_names'] = substr($symposium_abstract_author_names, 0, -2);

        $symposium_abstract_author_affiliations = '';
        if (strcmp(trim($_POST['symposium_first_author_affiliation']), "") != 0) {
          $symposium_abstract_author_affiliations = $symposium_abstract_author_affiliations . trim($_POST['symposium_first_author_affiliation']) . '@@';
        }
        if (strcmp(trim($_POST['symposium_second_author_affiliation']), "") != 0) {
          $symposium_abstract_author_affiliations = $symposium_abstract_author_affiliations . trim($_POST['symposium_second_author_affiliation']) . '@@';
        }
        if (strcmp(trim($_POST['symposium_third_author_affiliation']), "") != 0) {
          $symposium_abstract_author_affiliations = $symposium_abstract_author_affiliations . trim($_POST['symposium_third_author_affiliation']) . '@@';
        }
        if (strcmp(trim($_POST['symposium_fourth_author_affiliation']), "") != 0) {
          $symposium_abstract_author_affiliations = $symposium_abstract_author_affiliations . trim($_POST['symposium_fourth_author_affiliation']) . '@@';
        }
        if (strcmp(trim($_POST['symposium_fifth_author_affiliation']), "") != 0) {
          $symposium_abstract_author_affiliations = $symposium_abstract_author_affiliations . trim($_POST['symposium_fifth_author_affiliation']) . '@@';
        }
        if (strcmp(trim($_POST['symposium_sixth_author_affiliation']), "") != 0) {
          $symposium_abstract_author_affiliations = $symposium_abstract_author_affiliations . trim($_POST['symposium_sixth_author_affiliation']) . '@@';
        }
        if (strcmp(trim($_POST['symposium_seventh_author_affiliation']), "") != 0) {
          $symposium_abstract_author_affiliations = $symposium_abstract_author_affiliations . trim($_POST['symposium_seventh_author_affiliation']) . '@@';
        }
        if (strcmp(trim($_POST['symposium_eighth_author_affiliation']), "") != 0) {
          $symposium_abstract_author_affiliations = $symposium_abstract_author_affiliations . trim($_POST['symposium_eighth_author_affiliation']) . '@@';
        }
        if (strcmp(trim($_POST['symposium_ninth_author_affiliation']), "") != 0) {
          $symposium_abstract_author_affiliations = $symposium_abstract_author_affiliations . trim($_POST['symposium_ninth_author_affiliation']) . '@@';
        }
        $_SESSION['symposium_abstract_author_affiliations'] = substr($symposium_abstract_author_affiliations, 0, -2);

        $_SESSION['symposium_abstract'] = trim($_POST['symposium_abstract']);
        $_SESSION['symposium_keywords'] = trim($_POST['symposium_keywords']);

        $column_name = array('symposium_abstract_title', 'symposium_abstract_author_names', 'symposium_abstract_author_affiliations', 'symposium_abstract', 'symposium_keywords');
        $column_data = array($_SESSION['symposium_abstract_title'], $_SESSION['symposium_abstract_author_names'], $_SESSION['symposium_abstract_author_affiliations'], $_SESSION['symposium_abstract'], $_SESSION['symposium_keywords']);
        $symposium_tmp = array_combine($column_name, $column_data);

        if (isset($_SESSION['symposium_abstract_count'])) {
          $_SESSION['symposium_abstract_count'] = $_SESSION['symposium_abstract_count'] + 1;
        }
        else {
          $_SESSION['symposium_abstract_count'] = 0;
        }

        if (isset($_SESSION['symposium_tmp'])) {
          array_push($_SESSION['symposium_tmp'], $symposium_tmp);
        }
        else {
          $_SESSION['symposium_tmp'] = array();
          array_push($_SESSION['symposium_tmp'], $symposium_tmp);
        }

        unset($_SESSION['symposium_first_author_affiliation']);
        unset($_SESSION['symposium_first_author_name']);
        unset($_SESSION['symposium_second_author_affiliation']);
        unset($_SESSION['symposium_second_author_name']);
        unset($_SESSION['symposium_third_author_affiliation']);
        unset($_SESSION['symposium_third_author_name']);
        unset($_SESSION['symposium_fourth_author_affiliation']);
        unset($_SESSION['symposium_fourth_author_name']);
        unset($_SESSION['symposium_fifth_author_affiliation']);
        unset($_SESSION['symposium_fifth_author_name']);
        unset($_SESSION['symposium_sixth_author_affiliation']);
        unset($_SESSION['symposium_sixth_author_name']);
        unset($_SESSION['symposium_seventh_author_affiliation']);
        unset($_SESSION['symposium_seventh_author_name']);
        unset($_SESSION['symposium_eighth_author_affiliation']);
        unset($_SESSION['symposium_eighth_author_name']);
        unset($_SESSION['symposium_ninth_author_affiliation']);
        unset($_SESSION['symposium_ninth_author_name']);
        unset($_SESSION['symposium_abstract']);
        unset($_SESSION['symposium_keywords']);
        unset($_SESSION['symposium_abstract_title']);
        unset($_SESSION['symposium_error_msg']);

        $symposium_total_titles = '';
        for ($i = 0; $i < count($_SESSION['symposium_tmp']); $i++) {
          $symposium_total_titles = $symposium_total_titles . trim($_SESSION['symposium_tmp'][$i]['symposium_abstract_title']) . '~~';
        }
        $_SESSION['symposium_total_titles'] = substr($symposium_total_titles, 0, -2);

        $symposium_total_author_names = '';
        for ($i = 0; $i < count($_SESSION['symposium_tmp']); $i++) {
          $symposium_total_author_names = $symposium_total_author_names . trim($_SESSION['symposium_tmp'][$i]['symposium_abstract_author_names']) . '~~';
        }
        $_SESSION['symposium_total_author_names'] = substr($symposium_total_author_names, 0, -2);

        $symposium_total_author_affiliations = '';
        for ($i = 0; $i < count($_SESSION['symposium_tmp']); $i++) {
          $symposium_total_author_affiliations = $symposium_total_author_affiliations . trim($_SESSION['symposium_tmp'][$i]['symposium_abstract_author_affiliations']) . '~~';
        }
        $_SESSION['symposium_total_author_affiliations'] = substr($symposium_total_author_affiliations, 0, -2);

        $symposium_total_abstracts = '';
        for ($i = 0; $i < count($_SESSION['symposium_tmp']); $i++) {
          $symposium_total_abstracts = $symposium_total_abstracts . trim($_SESSION['symposium_tmp'][$i]['symposium_abstract']) . '~~';
        }
        $_SESSION['symposium_total_abstracts'] = substr($symposium_total_abstracts, 0, -2);

        $symposium_total_keywords = '';
        for ($i = 0; $i < count($_SESSION['symposium_tmp']); $i++) {
          $symposium_total_keywords = $symposium_total_keywords . trim($_SESSION['symposium_tmp'][$i]['symposium_keywords']) . '~~';
        }
        $_SESSION['symposium_total_keywords'] = substr($symposium_total_keywords, 0, -2);

        $_SESSION['abstract_titles'] = '';
        $_SESSION['abstract_author_names'] = '';
        $_SESSION['abstract_author_affiliations'] = '';
        $_SESSION['abstract_keywords'] = '';
        $_SESSION['abstract'] = '';

        $query = sprintf("INSERT INTO `submission`(username, affiliation, title, telephone, email, division, other_division, presentation_type, equipment, other_equipment,
                          abstract_title, abstract_author_names, abstract_author_affiliations, abstract_keywords, abstract,
                          symposium_titles, symposium_author_names, symposium_author_affiliations, symposium_keywords, symposium_abstracts,
                          regdate, ipaddress)
                          VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', ('%s'), '%s',
                                  '%s', '%s', '%s', '%s', '%s',
                                  '%s', '%s', '%s', '%s', '%s',
                                  NOW(), '%s');",
                          mysql_real_escape_string($_SESSION['username']),
                          mysql_real_escape_string($_SESSION['affiliation']),
                          mysql_real_escape_string($_SESSION['title']),
                          mysql_real_escape_string($_SESSION['telephone']),
                          mysql_real_escape_string($_SESSION['email']),
                          mysql_real_escape_string($_SESSION['division']),
                          mysql_real_escape_string($_SESSION['other_division']),
                          mysql_real_escape_string($_SESSION['presentation_type']),
                          mysql_real_escape_string($_SESSION['equipment']),
                          mysql_real_escape_string($_SESSION['other_equipment']),
                          mysql_real_escape_string($_SESSION['abstract_title']),
                          mysql_real_escape_string($_SESSION['abstract_author_names']),
                          mysql_real_escape_string($_SESSION['abstract_author_affiliations']),
                          mysql_real_escape_string($_SESSION['abstract_keywords']),
                          mysql_real_escape_string($_SESSION['abstract']),
                          mysql_real_escape_string($_SESSION['symposium_total_titles']),
                          mysql_real_escape_string($_SESSION['symposium_total_author_names']),
                          mysql_real_escape_string($_SESSION['symposium_total_author_affiliations']),
                          mysql_real_escape_string($_SESSION['symposium_total_keywords']),
                          mysql_real_escape_string($_SESSION['symposium_total_abstracts']),
                          mysql_real_escape_string($_SERVER['REMOTE_ADDR'])
                        );
        $db->sql_query($query);

        include("$ROOT_DIR/class.phpmailer.php");
        $mail = new PHPMailer();

        $mail->IsSMTP();
        $mail->SMTPAuth   = true;                   // enable SMTP authentication
        $mail->SMTPSecure = "ssl";                  // sets the prefix to the servier
        $mail->Host       = "smtp.gmail.com";       // sets GMAIL as the SMTP server
        $mail->Port       = 465;                    // set the SMTP port for the GMAIL server
        $mail->Username   = "sinuxing@gmail.com";   // GMAIL username
        $mail->Password   = "vn8p7dav";             // GMAIL password
        $mail->CharSet    = "utf8";

        $mail->SetFrom("b93102063@ntu.edu.tw", "第四十八屆台灣心理學年會");
        $mail->AddReplyTo("b93102063@ntu.edu.tw", "第四十八屆台灣心理學年會");
        $mail->AddAddress($_SESSION['email'], $_SESSION['username']);
        $mail->Subject  = "第四十八屆台灣心理學年會投稿確認信";

        $body = sprintf("%s 您好：\n\n感謝您的投稿，若您有任何疑問，十分歡迎您來信詢問，電子郵件地址：b93102063@ntu.edu.tw。\n\nThank you very much for your on-line registration. If any question, you are very much welcome to contact us on b93102063@ntu.edu.tw.\n\n\n第四十八屆台灣心理學年會", $_SESSION['username']);
        $mail->Body = $body;

        if (!$mail->Send()) {
          $_SESSION['error_msg'] = $mail->ErrorInfo;
          header("Location: failure.php");
        } else {
          header("Location: success.php");
        }
      }
      else {
        if (strcmp(trim($_POST['symposium_abstract_title']), "") != 0) {
          $_SESSION['symposium_abstract_title'] = trim($_POST['symposium_abstract_title']);
        }
        else {
          $_SESSION['symposium_abstract_title'] = '';
        }
        if (strcmp(trim($_POST['symposium_first_author_name']), "") != 0) {
          $_SESSION['symposium_first_author_name'] = trim($_POST['symposium_first_author_name']);
        }
        else {
          $_SESSION['symposium_first_author_name'] = '';
        }
        if (strcmp(trim($_POST['symposium_first_author_affiliation']), "") != 0) {
          $_SESSION['symposium_first_author_affiliation'] = trim($_POST['symposium_first_author_affiliation']);
        }
        else {
          $_SESSION['symposium_first_author_affiliation'] = '';
        }
        if (strcmp(trim($_POST['symposium_second_author_name']), "") != 0) {
          $_SESSION['symposium_second_author_name'] = trim($_POST['symposium_second_author_name']);
        }
        else {
          $_SESSION['symposium_second_author_name'] = '';
        }
        if (strcmp(trim($_POST['symposium_second_author_affiliation']), "") != 0) {
          $_SESSION['symposium_second_author_affiliation'] = trim($_POST['symposium_second_author_affiliation']);
        }
        else {
          $_SESSION['symposium_second_author_affiliation'] = '';
        }
        if (strcmp(trim($_POST['symposium_third_author_name']), "") != 0) {
          $_SESSION['symposium_third_author_name'] = trim($_POST['symposium_third_author_name']);
        }
        else {
          $_SESSION['symposium_third_author_name'] = '';
        }
        if (strcmp(trim($_POST['symposium_third_author_affiliation']), "") != 0) {
          $_SESSION['symposium_third_author_affiliation'] = trim($_POST['symposium_third_author_affiliation']);
        }
        else {
          $_SESSION['symposium_third_author_affiliation'] = '';
        }
        if (strcmp(trim($_POST['symposium_fourth_author_name']), "") != 0) {
          $_SESSION['symposium_fourth_author_name'] = trim($_POST['symposium_fourth_author_name']);
        }
        else {
          $_SESSION['symposium_fourth_author_name'] = '';
        }
        if (strcmp(trim($_POST['symposium_fourth_author_affiliation']), "") != 0) {
          $_SESSION['symposium_fourth_author_affiliation'] = trim($_POST['symposium_fourth_author_affiliation']);
        }
        else {
          $_SESSION['symposium_fourth_author_affiliation'] = '';
        }
        if (strcmp(trim($_POST['symposium_fifth_author_name']), "") != 0) {
          $_SESSION['symposium_fifth_author_name'] = trim($_POST['symposium_fifth_author_name']);
        }
        else {
          $_SESSION['symposium_fifth_author_name'] = '';
        }
        if (strcmp(trim($_POST['symposium_fifth_author_affiliation']), "") != 0) {
          $_SESSION['symposium_fifth_author_affiliation'] = trim($_POST['symposium_fifth_author_affiliation']);
        }
        else {
          $_SESSION['symposium_fifth_author_affiliation'] = '';
        }
        if (strcmp(trim($_POST['symposium_sixth_author_name']), "") != 0) {
          $_SESSION['symposium_sixth_author_name'] = trim($_POST['symposium_sixth_author_name']);
        }
        else {
           $_SESSION['symposium_sixth_author_name'] = '';
        }
        if (strcmp(trim($_POST['symposium_sixth_author_affiliation']), "") != 0) {
          $_SESSION['symposium_sixth_author_affiliation'] = trim($_POST['symposium_sixth_author_affiliation']);
        }
        else {
          $_SESSION['symposium_sixth_author_affiliation'] = '';
        }
        if (strcmp(trim($_POST['symposium_seventh_author_name']), "") != 0) {
          $_SESSION['symposium_seventh_author_name'] = trim($_POST['symposium_seventh_author_name']);
        }
        else {
          $_SESSION['symposium_seventh_author_name'] = '';
        }
        if (strcmp(trim($_POST['symposium_seventh_author_affiliation']), "") != 0) {
          $_SESSION['symposium_seventh_author_affiliation'] = trim($_POST['symposium_seventh_author_affiliation']);
        }
        else {
          $_SESSION['symposium_seventh_author_affiliation'] = '';
        }
        if (strcmp(trim($_POST['symposium_eighth_author_name']), "") != 0) {
          $_SESSION['symposium_eighth_author_name'] = trim($_POST['symposium_eighth_author_name']);
        }
        else {
          $_SESSION['symposium_eighth_author_name'] = '';
        }
        if (strcmp(trim($_POST['symposium_eighth_author_affiliation']), "") != 0) {
          $_SESSION['symposium_eighth_author_affiliation'] = trim($_POST['symposium_eighth_author_affiliation']);
        }
        else {
          $_SESSION['symposium_eighth_author_affiliation'] = '';
        }
        if (strcmp(trim($_POST['symposium_ninth_author_name']), "") != 0) {
          $_SESSION['symposium_ninth_author_name'] = trim($_POST['symposium_ninth_author_name']);
        }
        else {
          $_SESSION['symposium_ninth_author_name'] = '';
        }
        if (strcmp(trim($_POST['symposium_ninth_author_affiliation']), "") != 0) {
          $_SESSION['symposium_ninth_author_affiliation'] = trim($_POST['symposium_ninth_author_affiliation']);
        }
        else {
          $_SESSION['symposium_ninth_author_affiliation'] = '';
        }
        if (strcmp(trim($_POST['symposium_abstract']), "") != 0) {
          $_SESSION['symposium_abstract'] = trim($_POST['symposium_abstract']);
        }
        else {
          $_SESSION['symposium_abstract'] = '';
        }
        if (strcmp(trim($_POST['symposium_keywords']), "") != 0) {
          $_SESSION['symposium_keywords'] = trim($_POST['symposium_keywords']);
        }
        else {
          $_SESSION['symposium_keywords'] = '';
        }

        $_SESSION['symposium_error_msg'] = $symposium_error_msg;

        header("Location: submit.php");
      }
    }
  }
}
else {
  if ($is_indirect_link) {
    header("Location: submit.php");
  }
  else {
    if (strcmp(trim($_POST['username']), "") != 0) {
      $_SESSION['username'] = trim($_POST['username']);
    }
    else {
      $_SESSION['username'] = '';
    }
    if (strcmp(trim($_POST['affiliation']), "") != 0) {
      $_SESSION['affiliation'] = trim($_POST['affiliation']);
    }
    else {
      $_SESSION['affiliation'] = '';
    }
    if (strcmp(trim($_POST['title']), "") != 0) {
      $_SESSION['title'] = trim($_POST['title']);
    }
    else {
      $_SESSION['title'] = '';
    }
    if (strcmp(trim($_POST['telephone']), "") != 0) {
      $_SESSION['telephone'] = trim($_POST['telephone']);
    }
    else {
      $_SESSION['telephone'] = '';
    }
    if (strcmp(trim($_POST['email']), "") != 0) {
      $_SESSION['email'] = trim($_POST['email']);
    }
    else {
      $_SESSION['email'] = '';
    }
    if (!is_null($_POST['division'])) {
      $_SESSION['division'] = $_POST['division'];
    }
    if (strcmp(trim($_POST['other_division']), "") != 0) {
      $_SESSION['other_division'] = trim($_POST['other_division']);
    }
    else {
      $_SESSION['other_division'] = '';
    }
    if (!is_null($_POST['presentation_type'])) {
      $_SESSION['presentation_type'] = $_POST['presentation_type'];
    }
    if (!is_null($_POST['equipment'])) {
      $_SESSION['equipment'] = $_POST['equipment'];
    }
    else {
      $_SESSION['equipment'] = NULL;
    }
    if (strcmp(trim($_POST['other_equipment']), "") != 0) {
      $_SESSION['other_equipment'] = trim($_POST['other_equipment']);
    } else {
      $_SESSION['other_equipment'] = '';
    }

    $_SESSION['error_msg'] = $error_msg;

    header("Location: submit.php");
  }
}

?>